Get handle on other module to bring back name and latest baseline version

Hi all, I'm would like to bring back the latest baseline version and name of a number of different modules using their uniqueID. The reason for the uniqueID is that it is likely that the module will move to a different folder but I don't want to update the filepath each time the module moves so i'm hoping there is a way to do it by the uniqueID.

Here is the code I've written so far and it brings back the name and baseline version for the current module but I can't get it to recognise the module from a different folder. It appears to be getting a handle on the Item ok but I can't get the module to link to the item:

Module m = current 
Baseline b = getMostRecentBaseline(m) 
prot = (m."Name")" = v"(major b)"."(minor b)(suffix b)" "(annotation b)
 
Item i1 = itemFromID("48c520b3464303c3-0000e324")
Module m1 (Item i1)
Baseline b1 = getMostRecentBaseline(m1) 
busrul = (m1."Name")" = v"(major b)"."(minor b1)(suffix b1)" "(annotation b1)
 
 
m."Baseline Versions"= prot"\n"  busrul""

 


I'm only new to DXL so anny help would be appreciated and if that means scrapping my dxl completely, no worries.

Thanks,
Dan

 


dnmel0 - Mon Aug 15 22:24:58 EDT 2011

Re: Get handle on other module to bring back name and latest baseline version
Peter_Albert - Tue Aug 16 04:39:29 EDT 2011

Hi Dan,

it is not fully clear to me what you mean with "bring back the latest baseline version". From your code I would guess that your intention is only to report information on the latest baseline, which is easy to achieve. If you actually want to restore a Module to the baselined state, thus reverting all changes made since then, then be warned that this is not possible.

Anyhow, to your actual question. You failed to get a handle to the Module from the Item for two reasons: The first one is that you somehow got the respective DXL call wrong, and the second is that the other Module is not necessarily open.

The DXL call is

mod = module(itm)

where 'mod' must be a module variable, and 'itm' a item variable. You have

Module m1 (Item i1)

which for reasons I don't understand does not throw a DXL error, but also does not give you the correct Module handel neither.

Now, even if you change this line to

Module m1 = module(i1)

then still the Module handle might be null, if the Module is not open yet. You hence need an if clause to check, and a call to "read(Module mod)" if necessary.

It is in any case a good idea to always check for null handles to items, modules, objects, etc, to avoid errors at runtime. Another good idea is to use more "speaking" variable names than "m" and "b", which makes it first easier to find variables in longer source codes, secondly it makes it easier to understand the code, and thirdly it helps to avoid or find bugs like the one you have introduced in the "busrul = ..." line, where you call "(major b)" where you actually want to call "(major b1)".
A last issue is the advice to switch off variable Auto-declare, which forces you to define all variables, but also helps a lot in writing clearer code and avoiding bugs.

Below is a version of your code with all of the above applied, and with the last line modified to print the result, rather then setting the module level attribute of the current Module

Regards,

Peter
 

Module   currMod = current Module
Baseline currBas
string   prot, busrul
Item     itm
Module   otherMod
Baseline otherBas
bool     otherModuleWasOpen = true
if (!null currMod)
{ // Current Module is not null
  currBas = getMostRecentBaseline(currMod)
  if (!null currBas){prot = (name currMod)" = v"(major currBas)"."(minor currBas)(suffix currBas)" "(annotation currBas)}
  else              {prot = (name currMod)" : No baseline"}
  itm = itemFromID("00000972")
  if (!null itm)
  { // Item is not null
    Module m1 (Item i1)
    otherMod = module(itm)
    if (null otherMod){otherMod = read(fullName itm, false); otherModuleWasOpen = false}
    if (!null otherMod)
    { // Other Module is not null
      otherBas = getMostRecentBaseline(otherMod)
      if (!null otherBas){busrul = (name otherMod)" = v"(major otherBas)"."(minor otherBas)(suffix otherBas)" "(annotation otherBas)}
      else               {busrul = (name otherMod)" : No baseline"}
      if (!otherModuleWasOpen){close otherMod}
    } // Other Module is not null
    else {busrul = "Failed to open other Module"}
 
  } // Item is not null
  else {busrul = "Invalid item ID"}
  //currMod."Baseline Versions"= prot"\n"  busrul""
  print prot"\n"  busrul ""
} // Current Module is not null